#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll rd(){char c = getchar();ll f = 1,x = 0;
	while(!isdigit(c)){if(c == '-')f = -1;c = getchar();}
	while(isdigit(c))x = x * 10 + c - '0',c = getchar();
	return x * f;}
ll t,n,a[200005],f[2005][2005],s;
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	t = rd();while(t--){n = rd(),s = 0,memset(f,0,sizeof f);
		for(ll i = 1;i <= n;i++)a[i] = rd();
		for(ll i = 1;i <= n;i++)for(ll j = 1;j <= i;j++)s = max(s,f[i][j]),
			f[i + 1][i] = max(f[i + 1][i],f[i][j] + a[j] * (a[i+1] == a[j])),
			f[i + 1][j] = max(f[i + 1][j],f[i][j] + a[i] * (a[i+1] == a[i]));
		cout << s << '\n';
	}return 0;
}
